package operate;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BorrowBook implements MyInterface{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入所要借阅的书名：");
        Scanner sc = new Scanner(System.in);
        String name = sc.nextLine();

        int countSize = bookList.getUsedSize();
        for (int i = 0; i < countSize; i++) {
            Book book2 = bookList.getBook(i);
            if (book2.getName().equals(name)) {
                if(book2.isFlg() == true){
                    System.out.println("这本书已被借出");
                }else {
                    book2.setFlg(true);
                    System.out.println("借阅成功");
                }
                return;
            }
        }
        System.out.println("没有这本书");
    }
}
